<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;

class CreatePledgePropertyContractUses extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::create('pledge_property_contract_uses', function (Blueprint $table) {
            $table->id()->from(config('migration.from'));

            $table->text('address')->nullable()->comment('Адрес');
            $table->string('number')->nullable()->comment('Номер');

            $table->enum('total_area_type', ['meter', 'ga'])->default('meter')->comment('Тип площади');
            $table->string('total_area')->nullable()->comment('Общая площадь');

            $table->string('land_category')->nullable()->comment('Категория земель');
            $table->char('permitted_use')->nullable()->comment('Разрешенное использование');

            $table->enum('uses_type', ['year', 'month', 'date', 'infinity'])->default('year')->comment('Срок пользования');
            $table->string('uses')->nullable()->comment('Срок пользования');

            $table->enum('rent_confirmed', ['contract', 'order'])->default('contract')->comment('Подтверждающий документ');

            $table->string('contract_name')->nullable()->comment('Наименование договора');
            $table->date('contract_date')->nullable()->comment('Договор от');
            $table->string('contract_number')->nullable()->comment('Номер договора');
            $table->string('contract_tenant')->nullable()->comment('Арендатор');
            $table->date('contract_registered_date')->nullable()->comment('Дата регистрации');
            $table->string('contract_registered_company')->nullable()->comment('Компания регистрации');
            $table->string('contract_registered_number')->nullable()->comment('Номер регистрации');

            $table->string('order_company')->nullable()->comment('Наименование органа распоряжения');
            $table->string('order_number')->nullable()->comment('Номер распоряжения');
            $table->date('order_date')->nullable()->comment('Распоряжение от');

            $table->text('other_information')->nullable()->comment('Иные сведения');

            $table->jsonb('documents')->default(json_encode([]))->comment('Иные документы');
            $table->index('documents', null, 'gin');
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::dropIfExists('pledge_property_contract_uses');
    }
}
